package com.example.springDataJPA.hibernateAssociations;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.*;
import java.util.List;

/**
 * <pre>
 * 功能描述：
 * </pre>
 *
 * @author: 李明杰
 * @date: 2023/6/8 15:37
 */
@Entity
@Table(name = "jpa_teacher")
@Data
@AllArgsConstructor
@NoArgsConstructor
//@ToString(exclude = {"student"}) //双向关联
@ToString(exclude = {"studentTeachers"}) //双向关联
public class Teacher {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long teacherId;

    @Column(name = "name")
    private String teacherName;


    /**
     * 双向 oneToOne
     */
//    @OneToOne(mappedBy = "teacher",//mappedBy放弃使用外键约束，交给对方约束（填对方类中的属性名）
//            cascade = CascadeType.ALL,
//            orphanRemoval = true,
//            fetch = FetchType.LAZY)
//    private Student student;

    /**
     * 双向 OneToMany
     */
//    @OneToMany(mappedBy = "teacher",cascade = CascadeType.ALL)
//    private List<Student> students;

    /**
     * ManyToMany 开发常用情况
     */
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "teacher_id")
    private List<StudentTeacher> studentTeachers;

}
